﻿namespace KinonekoSoftware.Extensions.Collections
{
    partial class CollectionStatic
    {
        public static int IndexOf<T>(this IEnumerable<T> collection, Predicate<T> predicate)
        {
            if (predicate is null)
            {
                return -1;
            }

            if (collection is null)
            {
                return -1;
            }

            var i = 0;
            
            foreach (var item in collection)
            {
                if (predicate(item))
                {
                    return i;
                }

                i++;
            }

            return -1;
        }
    }
}